unit uTrack.local;

interface

uses uDebug.common, uDefs.local, SysUtils;

type
  //================================ TRACK
  TTrackItem = class( TObject )
  public
    TrackID  : integer;
    Area     : string;
    Country  : string;
    Speed    : integer;
    Aero     : integer;
    Distance : real;
    Grip     : real; // The track is slippy if it isnt used that often, it will improve over the course of each session.
    Weather  : integer; // 0 = dry, 100 = wet (for now anyway).
    LapRecord : TFastestLap;

    function FuelPerLap():real;
  end;
  TTrackList = class( TObject )
  public
    Items : array of TTrackItem;
    Count : integer;

    constructor Create;
    destructor Destroy; override;

    procedure Add(nTrackID:integer;nArea,nCountry:string;nSpeed,nAero:integer;nDistance,nGrip:real;nWeather:integer);
    procedure Clear;
  end;

implementation

function TTrackItem.FuelPerLap():real;
begin
  result := Distance * FUEL_USE_KM_L;
end;

  //================================ TRACK
constructor TTrackList.Create;
begin
  inherited Create;

  Count := 0;
  SetLength( Items, Count );
end;
destructor TTrackList.Destroy;
begin
  Count := 0;
  SetLength( Items, Count );

  inherited Destroy;
end;
procedure TTrackList.Add(nTrackID:integer;nArea,nCountry:string;nSpeed,nAero:integer;nDistance,nGrip:real;nWeather:integer);
begin
  DevConsole.Msg(ES_DEBUG, 'Adding Track '+nArea+' ['+nCountry+']');

  Inc( Count );
  SetLength(Items, Count);

  Items[ Count-1 ] := TTrackItem.Create();

  with Items[ Count-1 ] do
  begin
    TrackID  := nTrackID;
    Area     := nArea;
    Country  := nCountry;
    Speed    := nSpeed;
    Aero     := nAero;
    Distance := nDistance;
    Grip     := nGrip;
    Weather  := nWeather;

    LapRecord := TFastestLap.Create();
    LapRecord.SetTime(-1,-1,-1);
  end;
end;
procedure TTrackList.Clear;
begin
  Count := 0;
  SetLength( Items, Count );
end;

end.
